﻿using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid;
using MesProjectWinform.Entity.Request;
using MesProjectWinform.Public;
using MesProjectWinform.Public.Common;
using MesProjectWinform.WareHouse.Entity;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;

namespace MesProjectWinform.WareHouse.Form.审批
{
    public partial class Form_ProcessNodeItem : DevExpress.XtraEditors.XtraForm
    {
        public Form_ProcessNodeItem()
        {
            InitializeComponent();
        }
        List<ProcessNodesItemModel> NodeList = new List<ProcessNodesItemModel>();
        private void Form_ProcessNodeItem_Load(object sender, EventArgs e)
        {
            //try
            //{
            //    // 显示等待光标
            //    Cursor = Cursors.WaitCursor;
            //    lookUpEmpType();
            //    if (UpdateType)
            //    {
            //        // 新增模式
            //        this.Text = "新增";
            //        BtnAdd.Text = "新增";

            //        // 直接异步获取编码并设置到文本框
            //        string code = await GetCode(CodeType.Process);
            //        txtPRId.Text = code;

            //        //启用状态默认为是
            //        //toggleIsEnable.IsOn = true;
            //    }
            //    else
            //    {
            //        // 新增模式
            //        this.Text = "修改";
            //        BtnAdd.Text = "修改";

            //        // 绑定传入的数据到控件
            //        if (Current != null)
            //        {
            //            // 填充表单控件
            //            txtPRId.Text = Current.PRId;
            //            txtPRName.Text = Current.PRName;
            //            lookUpEMP.EditValue = Current.EmpId;
            //            txtMemo.Text = Current.Memo;
            //            //toggleIsEnable.IsOn = Current.IsEnable;

            //        }
            //    }

            //    // 初始化文件列表视图
            //    InitializeFileListView();

            //    // 初始化工序列表数据源
            //    InitProcessGridControl();

            //    // 处理查看模式
            //    if (IsViewMode)
            //    {
            //        // 设置窗体标题
            //        this.Text = "查看工艺流程";
            //        // 隐藏或禁用编辑按钮
            //        BtnAdd.Visible = false;
            //        BtnAddItem.Enabled = false;
            //        btnBrowseFile.Enabled = false;
            //        btnRemoveFile.Enabled = false;

            //        // 设置所有输入控件为只读
            //        txtPRId.ReadOnly = true;
            //        txtPRName.ReadOnly = true;
            //        txtMemo.ReadOnly = true;
            //        lookUpEMP.ReadOnly = true;
            //        Btn_Down.Visible = true;
            //        // 禁用工序项目表格的编辑功能（上移、下移、删除按钮）
            //        gridView1.OptionsBehavior.Editable = false;

            //        // 更改关闭按钮的文本
            //        BtnClose.Text = "关闭";
            //    }

            //    // 如果不是新增模式，且有传入工序项目和文件列表数据
            //    if (!UpdateType && processItemList != null && processItemList.Count > 0)
            //    {
            //        // 绑定工序项目数据到gridControl1
            //        gridControl1.DataSource = processItemList;
            //        gridControl1.RefreshDataSource();
            //    }

            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show("加载窗体时发生错误：" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
            //finally
            //{
            //    // 恢复光标
            //    Cursor = Cursors.Default;
            //}
        }

        #region  获取下拉框

        /// <summary>
        /// 下拉框类型部门填充
        /// </summary>
        public async void lookUpDepType()
        {
            HttpClientHelper helper = new HttpClientHelper();
            string action = $"WareHouse/BasicInfo/GetEMP";
            string json = helper.RequestUrlNew(RequestType.Get, action, null);

            ApiResult<List<EMP>> TypeModel = JsonConvert.DeserializeObject<ApiResult<List<EMP>>>(json);

            if (TypeModel != null && TypeModel.Code == ApiEnums.Success && TypeModel.Data != null)
            {

                lookUpEMP.Properties.ValueMember = "EMPID";
                lookUpEMP.Properties.DisplayMember = "EMPName";
                lookUpEMP.Properties.DataSource = TypeModel.Data;
                // 设置列显示
                lookUpEMP.Properties.Columns.Clear();
                lookUpEMP.Properties.Columns.Add(new LookUpColumnInfo("EMPID", "编码"));
                lookUpEMP.Properties.Columns.Add(new LookUpColumnInfo("EMPName", "名称"));
                lookUpEMP.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;

            }
        }

        /// <summary>
        /// 下拉框类型职位填充
        /// </summary>
        public async void lookUpJobType()
        {
            HttpClientHelper helper = new HttpClientHelper();
            string action = $"WareHouse/BasicInfo/GetEMP";
            string json = helper.RequestUrlNew(RequestType.Get, action, null);

            ApiResult<List<EMP>> TypeModel = JsonConvert.DeserializeObject<ApiResult<List<EMP>>>(json);

            if (TypeModel != null && TypeModel.Code == ApiEnums.Success && TypeModel.Data != null)
            {

                lookUpEMP.Properties.ValueMember = "EMPID";
                lookUpEMP.Properties.DisplayMember = "EMPName";
                lookUpEMP.Properties.DataSource = TypeModel.Data;
                // 设置列显示
                lookUpEMP.Properties.Columns.Clear();
                lookUpEMP.Properties.Columns.Add(new LookUpColumnInfo("EMPID", "编码"));
                lookUpEMP.Properties.Columns.Add(new LookUpColumnInfo("EMPName", "名称"));
                lookUpEMP.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;

            }
        }


        /// <summary>
        /// 下拉框类型人员填充
        /// </summary>
        public async void lookUpEmpType()
        {
            HttpClientHelper helper = new HttpClientHelper();
            string action = $"WareHouse/BasicInfo/GetEMP";
            string json = helper.RequestUrlNew(RequestType.Get, action, null);

            ApiResult<List<EMP>> TypeModel = JsonConvert.DeserializeObject<ApiResult<List<EMP>>>(json);

            if (TypeModel != null && TypeModel.Code == ApiEnums.Success && TypeModel.Data != null)
            {

                lookUpEMP.Properties.ValueMember = "EMPID";
                lookUpEMP.Properties.DisplayMember = "EMPName";
                lookUpEMP.Properties.DataSource = TypeModel.Data;
                // 设置列显示
                lookUpEMP.Properties.Columns.Clear();
                lookUpEMP.Properties.Columns.Add(new LookUpColumnInfo("EMPID", "编码"));
                lookUpEMP.Properties.Columns.Add(new LookUpColumnInfo("EMPName", "名称"));
                lookUpEMP.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;

            }
        }

        #endregion

    }
}